package com.wwt.springboot_vue.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Month;
import cn.hutool.core.date.Quarter;
import com.wwt.springboot_vue.bean.Notice;
import com.wwt.springboot_vue.common.Result;


import com.wwt.springboot_vue.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/echarts")
@RestController
public class EchartsController {

    @Autowired
    public NoticeMapper noticeMapper;

    @GetMapping("/example")
    public Result get(){
        Map<String, Object> map = new HashMap<>();
        map.put("x",CollUtil.newArrayList("Mon", "Tue"," Wed", "Thu", "Fri", "Sat", "Sun"));
        map.put("y",CollUtil.newArrayList(150, 230, 224, 218, 135, 147, 260));
        return  Result.success(map);
    }

    @GetMapping("/pienotice")
    public Result pienoticeEcharts(){
        List<Notice> list1 = noticeMapper.list();
        int q1 =0;//第一季度
        int q2 =0;//第2季度
        int q3 =0;//第3季度
        int q4 =0;//第4季度

        for (Notice notice: list1) {
            Date create_time = notice.create_time;
            Quarter  quarter = DateUtil.quarterEnum(create_time);
            switch (quarter){
                case Q1:q1 +=1;break;
                case Q2:q2 +=1;break;
                case Q3:q3 +=1;break;
                case Q4:q4 +=1;break;
                default:break;
            }
        }
        return  Result.success(CollUtil.newArrayList(q1,q2,q3,q4));
    }

    @GetMapping("/notice")
    public Result noticeEcharts(){
        List<Notice> list2 = noticeMapper.list();

        int m1 =0;//1月
        int m2 =0;//2月
        int m3 =0;//3月
        int m4 =0;//4月
        int m5 =0;//5月
        int m6 =0;//6月
        int m7 =0;//7月
        int m8 =0;//8月
        int m9 =0;//9月
        int m10 =0;//10月
        int m11 =0;//11月
        int m12 =0;//12月

        for (Notice notice: list2) {
            Date create_time = notice.create_time;
            Month   month = DateUtil.monthEnum(create_time);
            switch (month){

                case JANUARY:m1 +=1;break;
                case FEBRUARY:m2 +=1;break;
                case MARCH:m3 +=1;break;
                case APRIL:m4 +=1;break;
                case MAY:m5 +=1;break;
                case JUNE:m6 +=1;break;
                case JULY:m7 +=1;break;
                case AUGUST:m8 +=1;break;
                case SEPTEMBER:m9 +=1;break;
                case OCTOBER: m10 +=1;break;
                case NOVEMBER:m11 +=1;break;
                case DECEMBER:m12 +=1;break;
                default:break;

            }
        }
        return  Result.success(CollUtil.newArrayList(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12));
    }

}
